package org.proxycine.gestsalles.model.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Adapter {
	
	private Connection connexion;
	private Statement statement; 

	
	private void connect() throws ClassNotFoundException, SQLException {
		Class.forName("com.mysql.jdbc.Driver");
		connexion = DriverManager.getConnection("jdbc:mysql://localhost/GestSalles","root","CpZaHjS");
	}
	
	public Statement getStatement() {
		
		if(statement == null) {
			try {
				connect();
				statement = connexion.createStatement();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return statement;
	}
	
	public Connection getConnection() {
		if (connexion == null) {
			try {
				connect();				
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}	
		}
		
		return connexion;
	}
}
